import java.io.*;
import java.util.Scanner;

public class Test0 {

    //拷贝
    public  void testFileInputStream(){
        FileInputStream fs =null;
        BufferedReader br =null;
        FileOutputStream fr = null;
        try {
            fs =new FileInputStream("d:/a/a.txt");
            fr =new FileOutputStream("d:/a/b.txt");

            int i=0;
            while ((i=fs.read())!=-1){
            fr.write((char)i);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }catch (IOException e){
            e.printStackTrace();
        }
        finally {
            if (fs!=null){
                try {
                    fs.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
//追加
    public void testOutputStream(){
        Scanner sca =new Scanner(System.in);
        System.out.println("请输入你要追加的文字");
        String str=sca.next();
        FileOutputStream fo =null;
        try {
            fo=new FileOutputStream("d:/a/b.txt",true);
            fo.write(str.getBytes());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }catch (IOException e){
            e.printStackTrace();
        }
        finally {
            if (fo!=null){
                try {
                    fo.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }





    public static void main(String[] args) {
        Test0 test0=new Test0();
        test0.testFileInputStream();
//        System.out.println(a);
test0.testOutputStream();
    }
}
